package com.dz.fz.dao;

import org.apache.commons.dbcp2.BasicDataSource;

import javax.sql.DataSource;

public class DBCPDataSource {
    private static DataSource dataSource = null;

    public DBCPDataSource() {
    }

    public static DataSource getDataSource() {
        if(dataSource == null){
            BasicDataSource dbcpDataSource = new BasicDataSource();
            dbcpDataSource.setUrl("jdbc:mysql://localhost:3306/javaweb202004?serverTimezone=UTC&characterEncoding=utf8&useUnicode=true&useSSL=false");
            dbcpDataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
            dbcpDataSource.setUsername("root");
            dbcpDataSource.setPassword("199712");

            dbcpDataSource.setDefaultAutoCommit(true);
            //dbcpDataSource.setMaxActive(100);
            dbcpDataSource.setMaxIdle(30);
            //dbcpDataSource.setMaxWait(500);
            dataSource = (DataSource) dbcpDataSource;
        }
        return dataSource;
    }
}
